
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>file upload</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<body>

<div id="uploadForm">
    <input id="file" type="file" name="file"/>
    <button id="upload" type="button" onclick="fileUpload()">upload</button>
</div>



<script type="text/javascript">

    function fileUpload(){

        var formData = new FormData();
        formData.append('file', $('#file')[0].files[0]);
        $.ajax({
            type: 'POST',
            url: "http://"+window.location.host+"/upload",
            data: formData,
            processData: false,  // 告诉jQuery不要去处理发送的数据
            contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
            success: function (data) {
                alert(JSON.stringify(data));
            },
            error: function () {
                alert("上传失败");
            }
        });
    }

</script>
</body>
</html>